﻿using RXY_Mall.Core;
using System.Collections.Generic;

namespace RXY_Mall.Api.Alipay
{
    public class AlipayService
    {
        /// <summary>
        /// 支付宝签名
        /// </summary>
        /// <param name="out_trade_no"></param>
        /// <param name="body"></param>
        /// <param name="subject"></param>
        /// <param name="total_amount"></param>
        /// <returns></returns>
        public static string GetSign(string out_trade_no, string body, string subject, string total_amount)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("partner", AppConfig.AlipayPartner);
            parameters.Add("seller_id", AppConfig.AlipaySellerId);
            parameters.Add("out_trade_no", out_trade_no);
            parameters.Add("subject", subject.Replace(" ", ""));
            parameters.Add("body", body.Replace(" ", ""));
            parameters.Add("total_fee", total_amount);
            parameters.Add("notify_url", AppConfig.AlipayNotifyUrl);
            parameters.Add("service", "mobile.securitypay.pay");
            parameters.Add("payment_type", "1");
            parameters.Add("_input_charset", "utf-8");
            parameters.Add("it_b_pay", "30m");
            parameters.Add("show_url", "m.alipay.com");
            string sign = AlipaySignature.RSASign(parameters, Utils.GetMapPath(AppConfig.AlipayPrivateKeyPem), "utf-8", "RSA");
            sign = System.Web.HttpContext.Current.Server.UrlEncode(sign);
            parameters.Add("sign", sign);
            parameters.Add("sign_type", "RSA");
            return AlipaySignature.GetSignContent(parameters);
        }
    }
}